package com.enqualcomm.kids.manager;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.enqualcomm.kids.R;
import com.enqualcomm.kids.config.userdefault.TerminalDefault;
import com.enqualcomm.kids.mvp.map.MapPresenter;
import com.enqualcomm.kids.view.ImageUtils;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.HashMap;

import common.utils.MyLogger;

/**
 * Created by Sunzhigang on 2016/7/1.
 */
public class LocationModeHandlerImp1 implements LocationModeHandler {

    HashMap<String, Integer> mWeatherMap = new HashMap<String, Integer>() {
        {
            put("晴", R.drawable.w_b_sunny);
            put("多云", R.drawable.w_b_cloudy);
            put("阴", R.drawable.w_b_overcast);
            put("阵雨", R.drawable.w_b_shower);
            put("雷阵雨", R.drawable.w_b_thundershower);
            put("雷阵雨伴有冰雹", R.drawable.w_b_thundershower_with_hail);
            put("雨夹雪", R.drawable.w_b_sleet);
            put("小雨", R.drawable.w_b_light_rain);
            put("中雨", R.drawable.w_b_moderate_rain);
            put("大雨", R.drawable.w_b_heavy_rain);
            put("暴雨", R.drawable.w_b_storm);
            put("大暴雨", R.drawable.w_b_heavy_storm);
            put("特大暴雨", R.drawable.w_b_severe_storm);
            put("阵雪", R.drawable.w_b_snow_flurry);
            put("小雪", R.drawable.w_b_light_snow);
            put("中雪", R.drawable.w_b_moderate_snow);
            put("大雪", R.drawable.w_b_heavy_snow);
            put("暴雪", R.drawable.w_b_snowstorm);
            put("雾", R.drawable.w_b_foggy);
            put("冻雨", R.drawable.w_b_ice_rain);
            put("沙尘暴", R.drawable.w_b_duststorm);
            put("小到中雨", R.drawable.w_b_light_to_moderate_rain);
            put("中到大雨", R.drawable.w_b_moderate_to_heavy_rain);
            put("大到暴雨", R.drawable.w_b_heavy_rain_to_storm);
            put("暴雨到大暴雨", R.drawable.w_b_storm_to_heavy_storm);
            put("大暴雨到特大暴雨", R.drawable.w_heavy_to_severe_storm);
            put("小到中雪", R.drawable.w_b_light_to_moderate_snow);
            put("中到大雪", R.drawable.w_b_moderate_to_heavy_snow);
            put("大到暴雪", R.drawable.w_b_heavy_snow_to_snowstorm);
            put("浮尘", R.drawable.w_b_dust);
            put("扬沙", R.drawable.w_b_sand);
            put("强沙尘暴", R.drawable.w_b_sandstorm);
            put("霾", R.drawable.w_b_haze);
        }
    };


    @Override
    public void initLocationMode(Context context, TerminalDefault currentTermianal, MapPresenter mapPresenter, View rootRL, boolean autoLocationMode, boolean 是否支持计步, boolean 是否支持天气, boolean 是否老人手表) {
        SimpleDraweeView weather_iv = (SimpleDraweeView) rootRL.findViewById(R.id.weather_iv);
        TextView pedometer_tv = (TextView) rootRL.findViewById(R.id.pedometer_tv);
        TextView weather_tv = (TextView) rootRL.findViewById(R.id.weather_tv);


        if (是否支持计步 && autoLocationMode) {//只有智能模式才显示
            pedometer_tv.setVisibility(View.VISIBLE);
            String stepsToday = currentTermianal.getStepsToday();

            if (是否老人手表) {
                if (stepsToday != null) {
                    pedometer_tv.setText(context.getString(R.string.steps) + ":" + stepsToday);
                } else {
                    pedometer_tv.setText(context.getString(R.string.steps) + "：0");
                }
            } else {
                if (stepsToday != null) {
                    pedometer_tv.setText(stepsToday + "步");
                } else {
                    pedometer_tv.setText("0步");
                }
            }

        } else {
            pedometer_tv.setVisibility(View.INVISIBLE);
        }


        if (autoLocationMode && 是否支持天气) {
            String weatherType = currentTermianal.getWeatherType();

            if (weatherType != null) {
                try {
//                    int drawableId = mWeatherMap.get(weatherType);
//                    Uri.parse()
//                    weather_iv.setImageResource(drawableId);
                    weather_iv.setImageURI(Uri.parse(ImageUtils.getweatherPicPath(context, weatherType)));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String tmp = currentTermianal.getLowTemp() + "~" + currentTermianal.getHighTemp() + "°C";
                weather_tv.setText(tmp);
                weather_tv.setClickable(true);
            } else {
//                weather_iv.setImageResource(R.drawable.reai_w_cloudy);
                mapPresenter.locationSync();
                weather_tv.setText("");
            }
            weather_iv.setVisibility(View.VISIBLE);
        } else {
            weather_tv.setText("");
            weather_iv.setVisibility(View.INVISIBLE);
        }
    }
}
